<?php
header('Content-Type:text/html; charset=UTF-8');
session_start();
if (empty($_SESSION['user'])) {
    header('location:dl.php');
    exit();
}
$pdo = new PDO('mysql:dbname=dcxt;charset=utf8', 'root');
@$czh = $_SESSION['czh'];
@$ccm = $_SESSION['ccm'];
@$cplx = $_SESSION['cplx'];
@$zid = $_SESSION['zid'];
@$cid = $_SESSION['cid'];
@$sccp = $_SESSION['sccp'];
if ($cid != null && $zid != null) {
    $s3 = $pdo->prepare('insert into cpdingdan(caipinid,czid) values(:ss,:bb)');
    $s3->execute(array(
        'ss' => $cid,
        'bb' => $zid
    ));   
}
if ($sccp != null) {
    $s6 = $pdo->prepare('delete from cpdingdan where cpdingdan.id=:sccp');
    $s6->execute(array(
        'sccp' => $sccp
    ));
}
?>
<html>
<head>
<title>Bootstrap 模板</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
	charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="web/css/bootstrap.min.css" rel="stylesheet">
<script src="web/js/jquery-1.11.1.min.js"></script>
<script src="web/js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
		<script src="js/html5shiv.js"></script>
		<script src="js/respond.min.js"></script>
		<![endif]-->
</head>
<body>
	<?php include ('dh.php');?>
	<div class="container">
		<div class="row">
			<div class="col-xs-2">
				<form action="cxcpsj.php">
					<div class="input-group">
						<input type="text" class="form-control" name="czh"
							placeholder="桌号" />
						<div class="input-group-btn">
							<button type="submit" class="btn btn-default"
								style="height: 34px">
								<span class="glyphicon glyphicon-search"></span>
							</button>
						</div>
					</div>
				</form>
				<br />
				<div class="list-group">
					<?php
    $s1 = $pdo->prepare('select * from cz ');
    $s1->execute();
    $data1 = $s1->fetchAll(PDO::FETCH_NAMED);
    if ($czh == null) {
        for ($b = 0; $b < count($data1); $b ++) {
            ?>	
						<a class="list-group-item" style="color: blue"
						href="sjcf.php?zid=<?php echo $data1[$b]['id']?>"><?php echo $data1[$b]['czm'] ?></a>
						<?php
        }
    } else {
        $s7 = $pdo->prepare('select * from cz where cz.czm like :czh');
        $s7->execute(array(
            'czh' => '%' . $czh . '%'
        ));
        $dataczh = $s7->fetchAll(PDO::FETCH_NAMED);
        foreach ($dataczh as $zhm) {
            ?>
            <a class="list-group-item" style="color: blue"
						href="sjcf.php?zid=<?php echo $zhm['id']?>"><?php echo $zhm['czm'] ?></a>
            						<?php
        }
    }
    ?>
					</div>
			</div>
			<div class="col-xs-10">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<div class="row">
							<div class="col-xs-8">
								<div class="panel-title" style="margin-top: 5px">
									<span class="glyphicon glyphicon-ok"></span>
									<a href="#"><?php
        if ($zid != null) {
            $s2 = $pdo->prepare('select czm from cz where id=:ss');
            $s2->execute(array(
                'ss' => $zid
            ));
            $data2 = $s2->fetch(PDO::FETCH_NAMED);
            echo $data2['czm'];
        }
        ?></a>
									-已选菜品
								</div>
							</div>
							<div class="col-xs-4 text-right">
								<a href="ddlb.php?je=<?php 
								$s5 = $pdo->prepare('select sum(dj) as zj from cpdingdan join caipin on cpdingdan.caipinid=caipin.id where cpdingdan.czid=:cc');
								$s5->execute(array(
								    'cc' => $zid
								));
								$zj = $s5->fetch(PDO::FETCH_NAMED);
								echo $zj['zj']?>" class="btn btn-success ">
									结账
									<span class="badge">
									<?php
                                    echo $zj['zj'];
                                    ?>
									元</span>
								</a>
							</div>
						</div>
					</div>
					<div class="panel-body">
						<div class="row">
							<?php
    $s4 = $pdo->prepare('select * from  cpdingdan  join caipin on cpdingdan.caipinid=caipin.id where cpdingdan.czid=:cc');
    $s4->execute(array(
        'cc' => $zid
    ));
    $data4 = $s4->fetchAll(PDO::FETCH_NAMED);
    foreach ($data4 as $value) {
        ?>
								<div class="col-xs-2">
								<div class="thumbnail">
									<img style="width: 100px; height: 100px"
										src='<?php echo $value['imgurl']?>' />
									<div class="caption text-center">
										<?php echo $value['cm']?>
										<a
											href="sjcf.php?sccp=<?php echo $value['id'][0]?>&zid=<?php echo $zid?>">取消</a>
									</div>
								</div>
							</div>		
							<?php
    }
    ?>
							</div>
					</div>
					<div class="panel-heading">
						<div class="row">
							<div class="col-xs-6">
								<div class="panel-title" style="margin-top: 5px">
									<span class="glyphicon glyphicon-th-list"></span>
									<a href="#">可选菜品</a>
								</div>
							</div>
							<div class="col-xs-6">
								<form action="cxcpsj.php">
									<div class="input-group">
										<input class="form-control" name="ccm" placeholder="菜名" />
										<div class="input-group-btn">
											<select class="btn btn-default" name="cplx"
												style="height: 34px">
												<option value="">全部</option>
													<?php
            $s = $pdo->prepare('select * from cplx ');
            $s->execute();
            $data3 = $s->fetchAll(PDO::FETCH_NAMED);
            foreach ($data3 as $clx) {
                ?>
                                                      <option><?php echo $clx['lx']?></option>
                                                      <?php
            }
            ?>
												</select>
											<button class="btn btn-default" type="submit"
												style="height: 34px">
												<span class="glyphicon glyphicon-search"></span>
											</button>
										</div>
									</div>
								</form>
							</div>
						</div>
					</div>
					<div class="panel-body">
						<div class="row">			
							<?php
    $s = $pdo->prepare('select * from caipin ');
    $s->execute();
    $data = $s->fetchAll(PDO::FETCH_NAMED);
    if ($ccm == null && $cplx == null) {
        for ($a = 0; $a < count($data); $a ++) {
            ?>			
									<div class="col-xs-3">
								<div class="thumbnail">
									<img style="width: 150px; height: 150px"
										src='<?php echo $data[$a]['imgurl']?>' />
									<div class="caption text-center">
										<a
											href="sjcf.php?cid=<?php echo $data[$a]['id']?>&zid=<?php echo $zid?>"><?php echo $data[$a]['cm'].$data[$a]['dj']?>元</a>
									</div>
								</div>
							</div>
							<?php
        }
    } else {
        $s8 = $pdo->prepare('select * from caipin join cplx on caipin.lxid = cplx.id where caipin.cm like :cm and cplx.lx like :lx');
        $s8->execute(array(
            'cm' => '%' . $ccm . '%',
            'lx' => '%' . $cplx . '%'
        ));
        $data8 = $s8->fetchAll(PDO::FETCH_NAMED);
        foreach ($data8 as $scm) {
            ?>
            <div class="col-xs-3">
								<div class="thumbnail">
									<img style="width: 150px; height: 150px"
										src='<?php echo $scm['imgurl']?>' />
									<div class="caption text-center">
										<a
											href="sjcf.php?cid=<?php echo $scm['id'][0]?>&zid=<?php echo $zid?>">
											<?php echo $scm['cm'].$scm['dj']?>元
										</a>
									</div>
								</div>
							</div>
            								<?php
        }
    }
    ?>														
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
